//
//  NYSetPwdViewController.m
//  NYTYY
//
//  Created by MinLison on 2017/12/12.
//  Copyright © 2017年 NYtyy. All rights reserved.
//

#import "NYSetPwdViewController.h"
#import "NYRegisterNotNewUserViewController.h"
@interface NYSetPwdViewController ()<FXFormControllerDelegate>
@property(nonatomic, strong) FXFormController *formController;
@property(nonatomic, strong) NYUserSetPwdForm *form;
@end

@implementation NYSetPwdViewController

- (void)viewDidLoad
{
        [super viewDidLoad];
        
}
- (void)configForm
{
        self.form = [[NYUserSetPwdForm alloc] initWithType:self.type];
        self.formController = [[FXFormController alloc] init];
        self.formController.form = self.form;
        self.formController.delegate = self;
        self.formController.tableView = self.tableView;
}

- (void)configNavigationBar:(BaseNavigationBar *)navigationBar
{
        [super configNavigationBar:navigationBar];
        self.title = @"修改密码";
        
}
- (void)initSubviews
{
        [super initSubviews];
        [self configForm];
}
/// MARK: - Action
- (void)next
{
        [NYUserManager findPwd:nil success:^(NYUserModel * _Nonnull user) {
                [self successSetPwd];
        } failed:^(NSError * _Nonnull error) {
                [self failedSetPwd:error];
        }];
}

- (void)successSetPwd
{
        if (!NYUserManager.isUserInfoComplete)
        {
                @weakify(self);
                [self routeUrl:kNYUpdateUserInfoControllerURI param:nil handler:^(NSDictionary<NSString *,id> * _Nullable parameters, UIViewController<JLRRouteDefinitionTargetController> * _Nullable targetVC) {
                        @strongify(self);
                        NSMutableArray *array = [NSMutableArray array];
                        [array addObject:self.navigationController.viewControllers.firstObject];
                        [array addObject:targetVC];
                        [self.navigationController setViewControllers:array animated:YES];
                }];
        }
        else
        {
                
                [self.navigationController popToRootViewControllerAnimated:YES];
        }
}
- (void)failedSetPwd:(NSError * )error
{
        if (error.code == APP_ERROR_CODE_ERR_PHONE_ALLREADY_REGISTER)
        {
                NYRegisterNotNewUserViewController *vc = [[NYRegisterNotNewUserViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
        }
        else
        {
                [NYTipClass showErrorWithText:error.localizedDescription inView:self.view];
        }
}
/// MARK: - 导航栏 SubClassHolder
- (BOOL)forceEnableNavigationBarBackItem
{
        return YES;
}
+ (NYViewControllerNavigationBarType)navigationBarType
{
        return NYViewControllerNavigationBarTypeBlue;
}

@end
